<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <#assign base=request.contextPath  />
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css?t=1534970980648" media="all">
    <script src="${base}/frame/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.exedit.js"></script>
    <link rel="stylesheet" href="${base}/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${base}/css/zTreeStyle.css" type="text/css">
    <style type="text/css">
        form {
            padding: 10px;
        }
        .layui-btn-radius {
            border-radius: 3px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <div class="layui-form-item">
            <label class="layui-form-label">用户</label>
            <div class="layui-input-inline">
                <select id="name" lay-verify="required" class="isNull">
                    <option value="" selected>请选择...</option>
                    <#list user as user>
                        <option value="${user.id}">${user.nickName}</option>
                    </#list>
                </select>
            </div>

        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-form-item">
            <label class="layui-form-label">小区</label>
            <div class="layui-input-inline">
                <select id="quartersId" lay-verify="required" class="isNull">
                    <option value="" selected>请选择...</option>
                <#--<#list quarters as quarters>-->
                        <#--<option value="${quarters.id}">${quarters.quartersName}</option>-->
                <#--</#list>-->
                </select>
            </div>

        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">楼室</label>
            <div class="layui-input-inline">
                <input name="detailedFloor" id="detailedFloor" lay-verify="required" autocomplete="off" class="layui-input "
                       type="text">
            </div>

        </div>
    </div>




    <div class="layui-form-item" style="margin-left: 30px">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="formDemo" lay-submit="" type="button"
                    id="onInsert" style="background-color: #0092EF;position: relative; left: 50%;">立即提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary" style="position: relative; left: 50%;">重置</button>
        </div>
    </div>
    </div>
</form>

<script>

    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;


        $.ajax({
            type: "get", //提交方式
            url: "${base}/admin/quarters/llist",//路径
            dataType: "json",
            async: false,
            success: function (data) {//返回数据根据结果进行相应的处理
                for (var i = 0; i < data.length; i++) {
                    $("#quartersId").append(
                            ' <option value="' + data[i].id + '"  >' + data[i].name + '</option>'
                    )
                }
                form.render(); //更新全部
            }
        });


    });



    //添加
    $("#onInsert").one("click",function(){

        if($("#name").val()==""){
            layer.msg("请选择用户")
            return;
        }
        if($("#quartersId").val()==""){
            layer.msg("请选择小区")
            return;
        }
        if($("#detailedFloor").val()==""){
            layer.msg("楼室不能为空")
            return;
        }



        $.ajax({
            type: "POST", //提交方式
            url: "${base}/admin/user/updateByIdUser",//路径
            data: {userId:$("#name").val(),quartersId:$("#quartersId").val(),detailedFloor:$("#detailedFloor").val()},
            success: function (data) {//返回数据根据结果进行相应的处理
                if (data == 1) {
                    layer.msg("操作成功");
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }, 300)
                    var table = parent.layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/admin/user/selectMyPage'
                        , where: {} //设定异步数据接口的额外参数
                    });
                } else if(data==2){
                    layer.msg("该用户已存在小区");
                }else{
                    layer.msg("操作失败");
                }
            }
        });
    })
</script>
</body>
</html>
